package com.cictec.middleware.tde.rm.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cictec.middleware.commons.utils.DateUtils;
import com.cictec.middleware.commons.utils.PMSUtils;
import com.cictec.middleware.commons.utils.Result;
import com.cictec.middleware.commons.utils.ResultUtil;
import com.cictec.middleware.core.entity.Device;
import com.cictec.middleware.core.pojo.MiddlewareDriverSign;
import com.cictec.middleware.core.pojo.MiddlewarePosition;
import com.cictec.middleware.feign.distribute.MiddlewareDeviceService;
import com.cictec.middleware.feign.distribute.MiddlewareDriverService;
import com.cictec.middleware.feign.distribute.MiddlewarePositionService;
import com.cictec.middleware.tde.SendTerminalMessageService;
import com.cictec.middleware.tde.rm.service.RmSendTerminalMessageService;

/**
 * 【锐明协议】中间件客户端下发消息Controller
 * 
 * @author Administrator
 *
 */
@RestController
@RequestMapping("/tde")
public class RmSendTerminalMessageController implements SendTerminalMessageService {

	@Autowired
	private RmSendTerminalMessageService rmSendTerminalMessageService;
	@Autowired
	private MiddlewarePositionService middlewarePositionService;
	@Autowired
	private MiddlewareDriverService middlewareDriverService;
	@Autowired
	private MiddlewareDeviceService middlewareDeviceService;

	@RequestMapping(value = "/test")
	public Result test() {
		MiddlewarePosition position = new MiddlewarePosition(PMSUtils.getUUID());
		position.setLat(37.44965398519488);
		position.setLng(118.50812108525868);
		position.setSpeed(30);
		position.setLineId(3);
		position.setDevCode("440");
		position.setCreateTime(new Date());
		position.setSendTime(new Date());
		
//		return middlewareDeviceService.deviceConnectByDevcode("440");
//		return ResultUtil.getSuccessResult(middlewareDeviceService.getDeviceByDevCode("440"));
//		return ResultUtil.getSuccessResult(middlewareDeviceService.getDeviceBySerialNumber("00820070C2"));
//		return middlewarePositionService.positionUpload(position);
		
		String devCode = "13069";
		Date signTime = new Date();
		Device device = middlewareDeviceService.getDeviceByDevCode(devCode);
		MiddlewareDriverSign driverSign = new MiddlewareDriverSign(device.getCityCode(), devCode, "003642", signTime);
		Result result = middlewareDriverService.driverSign(driverSign);
		return result;
		
	}
	
	@RequestMapping("/sendTextMessage")
	public Result sendTextMessage(String devCode, String lineId, String content) {
		// TODO Auto-generated method stub
		return rmSendTerminalMessageService.sendTextMessage(devCode, lineId, content);
	}

	@RequestMapping("/sendTextVoiceMessage")
	public Result sendTextVoiceMessage(String devCode, String lineId, String content) {
		// TODO Auto-generated method stub
		return rmSendTerminalMessageService.sendTextVoiceMessage(devCode, lineId, content);
	}

	@RequestMapping("/sendBeforAfterDistanceMessage")
	public Result sendBeforAfterDistanceMessage(String devCode, String lineId, String content) {
		// TODO Auto-generated method stub
		return rmSendTerminalMessageService.sendBeforAfterDistanceMessage(devCode, lineId, content);
	}

	@RequestMapping("/sendDepartureTimeMessage")
	public Result sendDepartureTimeMessage(String devCode, String lineId, String content) {
		// TODO Auto-generated method stub
		return rmSendTerminalMessageService.sendDepartureTimeMessage(devCode, lineId, content);
	}

	@RequestMapping("/sendChangeLineMessage")
	public Result sendChangeLineMessage(String devCode, String newLineId, String direction) {
		// TODO Auto-generated method stub
		return rmSendTerminalMessageService.sendChangeLineMessage(devCode, newLineId, direction);
	}

	@RequestMapping("/sendChangeOperateMessage")
	public Result sendChangeOperateMessage(String devCode, String typeValue, int operateStatus, String content) {
		// TODO Auto-generated method stub
		return rmSendTerminalMessageService.sendChangeOperateMessage(devCode, typeValue, operateStatus, content);
	}

	@RequestMapping("/sendUploadReportStationFileMessage")
	public Result sendUploadReportStationFileMessage(String devCode, Object data) {
		// TODO Auto-generated method stub
		return rmSendTerminalMessageService.sendUploadReportStationFileMessage(devCode, data);
	}

}
